package com.kobeliu.entity;

/**
 * 剑指 05 简单题
 * 傻瓜题 属于是
 *
 * 请实现一个函数，把字符串 s 中的每个空格替换成"%20"。
 * 示例 1：
 *
 * 输入：s = "We are happy."
 * 输出："We%20are%20happy."
 *
 */

public class Demo_31_sword_5 {

    public static void main(String[] args) {

        System.out.println(replaceSpace("We are happy"));
        System.out.println(reverseLeftWords("Wearehappy",3));
    }

    public static String replaceSpace(String s) {

        StringBuffer sb = new StringBuffer(s);

        for (int i = 0; i < sb.length(); i++) {
            if(sb.charAt(i)==' '){
                sb.replace(i,i+1,"%20");
            }
        }
        return sb.toString();

    }

    public static String reverseLeftWords(String s, int n) {

        String head = s.substring(0,n);
        String tail = s.substring(n);

        return tail+head;



    }
}
